package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.BFDetailReport;

public class BFDetailReportPresenter extends AbstractPresenter<BFDetailReport> {
	final String SINGLEITEM = "details";
	final String MULTIITEM = "detailss";
	
	public ArrayList<BFDetailReport> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public BFDetailReport tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public BFDetailReport createItemFromJSONObject(JSONObject jsonObject){
		BFDetailReport item = new BFDetailReport();
		try{
			item.setBrewDate(getDateFromString(jsonObject.getString("brewDate")));
			item.setDueDate(getDateFromString(jsonObject.getString("dueDate")));
			item.setVol(jsonObject.getDouble("vol"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(BFDetailReport item){
		try{
			JSONObject json = new JSONObject();
			json.put("dueDate", getDate(item.getDueDate()));
			json.put("brewDate", getDate(item.getBrewDate()));
			json.put("vol", item.getVol());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public BFDetailReport getEmptyEntity(){
		BFDetailReport entity = new BFDetailReport();
		return entity;
	}
}
